all: asciidoc2html asciidoc2docbook dokk.json

# Convert articles to DOCBOOK
asciidoc2docbook : $(subst :,\:,$(shell find ./articles -type f -name "*.adoc" | sed -E 's/^.*\/(.*)\.adoc$$/docbook\/\1.dbk/'))
docbook/%.dbk : articles/%.adoc
	@ADOC="$<"
	@DBK="$@"
	
	@echo "$$ADOC -> $$DBK"
	
	# Check "./docbook" exists
	mkdir --parents docbook
	
	# Convert ASCIIDOC to DOCBOOK
	@asciidoc --backend docbook --doctype book --out-file "$$DBK" "$$ADOC"

# Convert articles to HTML
asciidoc2html : $(subst :,\:,$(shell find ./articles -type f -name "*.adoc" | sed -E 's/^.*\/(.*)\.adoc$$/html\/\1.html/'))
html/%.html : articles/%.adoc
	@ADOC="$<"
	@HTML="$@"
	
	@echo "$$ADOC -> $$HTML"
	
	# Check "./html" exists
	mkdir --parents html
	
	# Convert ASCIIDOC to HTML
	@asciidoc --backend html5 --doctype book --no-header-footer \
                  --out-file "$$HTML" "$$ADOC"

# Find which nodes link to which. Used for dokk.org/explore
dokk.json: dokk.ttl
	./relations.py

clean:
	rm --force --recursive docbook html

.ONESHELL:
.SUFFIXES:
.PHONY:
.DELETE_ON_ERROR:
